let RouterPlugin = function () {
  this.$router = null
  this.$store = null
}
RouterPlugin.install = function (vue, router, store, i18n) {
  this.$router = router
  this.$store = store
  this.$vue = new vue({ i18n })

  // 这个的作用是 为了检查出网页链接，因为本项目用到了 iframe
  function isURL(s) {
    if (s.includes('html')) return true
    return /^http[s]?:\/\/.*/.test(s)
  }

  // 将参数处理为参数的形式拼接
  function objToform(obj) {
    let result = []
    Object.keys(obj).forEach((ele) => {
      result.push(`${ele}=${obj[ele]}`)
    })
    return result.join('&')
  }

  this.$router.$avueRouter = {
    //全局配置
    routerList: [],
    group: '',
    meta: {},
    safe: this,
    //处理路由
    getPath: function (params) {
      let { src } = params
      let result = src || '/'
      if (isURL(src)) {
        result = `/myiframe/urlPath?${objToform(params)}`
      }
      return result
    },
    //正则处理路由
    vaildPath: function (list, path) {
      let result = false
      list.forEach((ele) => {
        if (new RegExp('^' + ele + '.*', 'g').test(path)) {
          result = true
        }
      })
      return result
    },
    //设置路由值
    getValue: function (route) {
      let value = ''
      if (route.query.src) {
        value = route.query.src
      } else {
        value = route.path
      }
      return value
    }
  }
}
export default RouterPlugin
